package net.child.chess.pieces;

import net.child.chess.utils.Position;

//	In several cases we will do fake pieces moves, so we need somehow to save the current
//	state of the piece and restore it after the fake moves.
public class PieceState 
{
	public PieceState(int position, boolean wasMoved)
	{
		mPosition = new Position(position);
		mWasMoved = wasMoved;
	}
	
	public PieceState(Position position, boolean wasMoved)
	{
		mPosition = new Position(position);
		mWasMoved = wasMoved;
	}
	
	public PieceState(PieceState state)
	{
		mPosition = new Position(state.position());
		mWasMoved = state.mWasMoved;
	}
	
	public PieceState saveState()
	{
		return new PieceState(mPosition, mWasMoved);
	}
	
	public void restoreState(PieceState state)
	{
		mPosition.position(state.mPosition);
		mWasMoved = state.mWasMoved;
	}
	
	public void move(int position)
	{
		mWasMoved = (mPosition.position() != position);
		mPosition.position(position);
	}
	public Position position()
	{
		return mPosition;
	}
	
	public boolean wasMoved()
	{
		return mWasMoved;
	}
	
	Position mPosition;
	boolean mWasMoved;
}
